/*
Web: http://www.jsForms.com
Copyright (C) 2008  Igor Demyanov (mailto:Igor.Demyanov@gmail.com)
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
jsForms.Components.jsFormsEditor={
	Version:"0.6",
	Init:function()
	{
		cssController.Init();
		this.C.SplashName.text('jsForms editor');
		this.C.SplashVersion.text('v'+this.Version);
		this.C.Splash.animate({opacity:0},3000,function(){$(this).remove();});
		this.C.WinEdit.hide();
		this.C.WinLoad.hide();
		this.C.WinNew.hide();
		return jsForms.Components.Component.Init.call(this);
	},
	bLoad_onClick:function()
	{
		this.C.background._SetEvent('onShow',this,this.ShowLoadDialog);
		this.C.background.Show();
	},
	ShowLoadDialog:function()
	{
		this.C.WinLoad.show();
	},
	LoadDialog_Cancel:function()
	{
		this.C.WinLoad.hide();
		this.C.background.Hide();
	},
	bNew_onClick:function()
	{
		this.C.background._SetEvent('onShow',this,this.ShowNewDialog);
		this.C.background.Show();
	},
	
	ShowNewDialog:function()
	{
		this.C.WinNew.show();
	},
	NewDialog_Ok:function(compType)
	{
		this.C.WinNew.hide();
		this.C.background.Hide();
		var result = jsForms.DesignMode.CreateEmptyComponent(compType,'<div/>');
		if (result && result.error!=undefined)
		{
			alert(result.error);
			return;
		}
		this.EditComponent(compType);
	},
	NewDialog_Cancel:function()
	{
		this.C.WinNew.hide();
		this.C.background.Hide();
	},
	bEdit_onClick:function()
	{
		this.C.background._SetEvent('onShow',this,this.ShowEditDialog);
		this.C.background.Show();
	},
	ShowEditDialog:function()
	{
		this.C.DialogEdit.FillComponentList();
		this.C.WinEdit.show();
	},
	EditComponent:function(compType)
	{
		var newTab = jsForms.CreateComponent('TabItem');
		var ce = jsForms.CreateComponent('ComponentEditor');
		ce.SetComponentName(compType);
		newTab.AppendContent(ce);
		newTab.SetTitle(compType);
		newTab._AddComponent(ce);
		this.C.jsFETabs.AppendTab(newTab);
		newTab.Init();
	},
	EditDialog_Ok:function(compType)
	{
		this.C.WinEdit.hide();
		this.C.background.Hide();
		this.EditComponent(compType);
	},
	EditDialog_Cancel:function()
	{
		this.C.WinEdit.hide();
		this.C.background.Hide();
	}
};
